#!/usr/bin/env ansible-playbook
---
- hosts: localhost
  vars:
    ansible_ask_become_pass: true
    configs:
    - awesome
    - picom
    - redshift

  tasks:
  - name: "Install Xorg"
    community.general.pacman:
      name: 
      - xorg
      - xorg-xinit # X.Org initialisation program
      - mesa # An open-source implementation of the OpenGL specification
      - vulkan-radeon # Radeon's Vulkan mesa driver
      - xorg-fonts-100dpi # X.org 100dpi fonts
      - xclip # Command line interface to the X11 clipboard
      - upower # Abstraction for enumerating power devices, listening to device events and querying history and statistics
      - arandr # Provide a simple visual front end for XRandR 1.2.
      - autorandr # Auto-detect connected display hardware and load appropiate X11 setup using xrandr
      state: latest
    become: yes

  - name: "Enable Autorandr"
    ansible.builtin.systemd:
      name: autorandr
      enabled: yes
    become: yes

  - name: "Lookup for HiDPI configs"
    ansible.builtin.find: 
      paths: "{{ playbook_dir }}/config/hidpi"
      hidden: yes
    register: hidpi

  - name: "Create symlinks for configurations"
    ansible.builtin.file:
      src: "{{ playbook_dir }}/config/hidpi/{{ item.path | basename }}"
      dest: "~/{{ item.path | basename }}"
      state: link
      owner: 1000
      group: 1000
    loop: "{{ hidpi.files }}"

  - name: "Install Fonts"
    community.general.pacman:
      name: 
      - noto-fonts # Google Noto TTF fonts
      - noto-fonts-emoji # Google Noto emoji fonts
      - noto-fonts-cjk # Google Noto CJK fonts
      - noto-fonts-extra # Google Noto TTF fonts - additional variants
      - ttf-ubuntu-mono-nerd # Patched font Ubuntu Mono from nerd fonts library
      - ttf-dejavu-nerd # Patched font Dejavu Sans Mono from nerd fonts library
      - ttf-firacode-nerd # Patched font Fira (Fura) Code from nerd fonts library
      - otf-firamono-nerd # Patched font Fira (Fura) Mono from nerd fonts library
      update_cache: yes
      state: latest
    become: yes

  - name: "Create symlinks for configurations"
    ansible.builtin.file:
      src: "{{ playbook_dir }}/config/{{ item }}"
      dest: "~/.config/{{ item }}"
      state: link
      owner: 1000
      group: 1000
    loop: "{{ configs }}"

  - name: "Install Awesome"
    community.general.pacman:
      name: 
      - awesome # Highly configurable framework window manager
      - picom # X compositor that may fix tearing issues
      update_cache: yes
      state: latest
    become: yes

  - name: "Install Auxiliary WM applications"
    community.general.pacman:
      name: 
      - dmenu # Generic menu for X
      - clipmenu # Clipboard management using dmenu
      update_cache: yes
      state: latest
    become: yes

  - name: "Install SDDM"
    community.general.pacman:
      name: 
      - sddm # QML based X11 and Wayland display manager
      state: latest
    become: yes

  - name: "Install SDDM theme"
    kewlfft.aur.aur:
      name:
      - sddm-sugar-dark
      state: latest
    become: yes
    become_user: aur_builder

  - name: "Copy SDDM configuration"
    ansible.builtin.copy:
      src: "{{ playbook_dir }}/config/sddm/"
      dest: "/etc/sddm.conf.d/"
    become: yes

  - name: "Enable SDDM"
    ansible.builtin.systemd:
      name: sddm
      enabled: yes
    become: yes

  - name: "Pinentry for Dmenu"
    kewlfft.aur.aur:
      name:
      - pinentry-dmenu # A pinentry program with the charm of dmenu
      state: latest
    become: yes
    become_user: aur_builder

  - name: "Symlink .gnupg configuration"
    ansible.builtin.file:
      src: "{{ playbook_dir }}/config/gnupg/gpg-agent.conf"
      dest: "~/.gnupg/gpg-agent.conf"
      state: link
      owner: 1000
      group: 1000

  - name: "Install Redshift"
    community.general.pacman:
      name: 
      - redshift # Adjusts the color temperature of your screen according to your surroundings.
      update_cache: yes
      state: latest
    become: yes

  - name: Enable Redshift
    ansible.builtin.systemd:
      name: redshift
      state: started
      enabled: yes
      scope: user
...
